package com.xf.web.controller.sys;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import com.xf.sys.entity.SysMenu;
import com.xf.sys.entity.SysResource;
import com.xf.sys.service.ISysMenuService;
import com.xf.sys.service.ISysResourcesRoleService;
import com.xf.web.util.SessionUtil;

/**
 *IndexController.java
 *IndexController
 *author:lb
 *date:2016年11月4日
 */
@Controller
public class IndexController {

	@Autowired
	private ISysMenuService sysMenuService;
	
	@Autowired
	private ISysResourcesRoleService sysResourcesRoleService;
	
	@RequestMapping("/op_{oper}_{id}")
	public String op(@PathVariable String oper, @PathVariable Integer id,Model model)
	{
		SysMenu sysMenu =sysMenuService.selectSysMenu(id);
		if(sysMenu!=null){
			Map<String, Integer> map=new HashMap<String, Integer>();
			map.put("roleId",SessionUtil.getSession().getRoleId());
			map.put("menuId",id);
			List<SysResource> list=sysResourcesRoleService.selectSysResourceRoleList(map);
			
			if(list.isEmpty())return "denied";//无权限
			model.addAttribute("operates", list);
			model.addAttribute("OP",list.get(0));
			model.addAttribute("MENU",this.sysMenuService.selectSysMenu(id));// 获取对应的菜单对象
			return "forward:" + sysMenu.getMenuUrl()+ "/" + oper + ".do";
		}
		return "404";
	}

	
}
